package com.example.leero.graduation.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.example.leero.graduation.R;
import com.example.leero.graduation.Util.ImageLoader;
import com.example.leero.graduation.Util.StringUtil;
import com.example.leero.graduation.model.Rank;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by Leero on 2017-5-12.
 */

public class RankAdapter extends CommonAdapter<Rank> {
    private Context context;

    public RankAdapter(Context context, int layoutId, List<Rank> datas) {
        super(context, layoutId, datas);
        this.context = context;
    }

    @Override
    protected void convert(ViewHolder holder, Rank rank, int position) {
        holder.setText(R.id.tv_rank_num, (position+1) + "");
        holder.setText(R.id.tv_user_name, rank.name);
        holder.setText(R.id.tv_mileage, "跑了" + (rank.mileage / 1000) + "Km");

        ImageView avatar = holder.getView(R.id.iv_avatar);
        if (!StringUtil.isEmpty(rank.avatar)) {
            ImageLoader.load(context, avatar, rank.avatar);
        } else {
            avatar.setImageResource(R.drawable.default_avatar_cricle);
        }
    }
}
